package com.elm.po;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;

public class Awards implements java.io.Serializable {
    @Setter
    @Getter
    private Long id;

    @Setter
    @Getter
    private BigDecimal award_amount;

    @Setter
    @Getter
    private BigDecimal recharge_amount;

    // 充血模型：在领域对象中封装业务逻辑
    public void updateAwardsInfo(BigDecimal rechargeAmount, BigDecimal awardAmount) {
        if (rechargeAmount == null || rechargeAmount.compareTo(BigDecimal.ZERO) <= 0) {
            throw new IllegalArgumentException("充值金额必须大于0");
        }
        if (awardAmount == null || awardAmount.compareTo(BigDecimal.ZERO) < 0) {
            throw new IllegalArgumentException("奖励金额不能为负数");
        }
        this.recharge_amount = rechargeAmount;
        this.award_amount = awardAmount;
    }

    public void validateForCreation() {
        if (this.id == null) {
            throw new IllegalArgumentException("ID不能为空");
        }
        if (this.recharge_amount == null || this.recharge_amount.compareTo(BigDecimal.ZERO) <= 0) {
            throw new IllegalArgumentException("充值金额必须大于0");
        }
        if (this.award_amount == null || this.award_amount.compareTo(BigDecimal.ZERO) < 0) {
            throw new IllegalArgumentException("奖励金额不能为负数");
        }
    }

    public static Awards createAwards(Long id, BigDecimal rechargeAmount, BigDecimal awardAmount) {
        Awards awards = new Awards();
        awards.setId(id);
        awards.setRecharge_amount(rechargeAmount);
        awards.setAward_amount(awardAmount);
        awards.validateForCreation();
        return awards;
    }
}